/*
 * StartupScreen.java
 *
 * Created on May 15, 2007, 6:34 PM
 *
 * Copyright (c) 2007 Daniel Gronau
 *
 * This file is part of KanjiTori.
 *
 * KanjiTori is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * KanjiTori is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

package kanjitori.graphics.ortho.status;

import com.jme.scene.Node;
import com.jme.scene.shape.Quad;
import com.jme.system.DisplaySystem;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import kanjitori.graphics.ortho.Ortho;
import kanjitori.util.Cache;

/**
 *
 * @author DGronau
 */
public class StartupScreen extends Ortho {
    
    private final static Font FONT = Cache.getFont("Arial Unicode MS", Font.PLAIN, 25);
    
    private Image image;
    private Quad startupQuad;
    
    private int picWidth;
    private int picHeight;
    
    /** Creates a new instance of StartupScreen */
    public StartupScreen(Image image) {
        this.image = image;
        initScreen();
        updateScreen(0,"");
    }
    
    private void initScreen() {
        node = new Node("startup");
        
        int width = DisplaySystem.getDisplaySystem().getWidth();
        int height = DisplaySystem.getDisplaySystem().getHeight();
        
        picWidth = image.getWidth(null);
        picHeight = image.getHeight(null);
        
        Rectangle startupPos = new Rectangle((width - picWidth)/2, (height + picHeight)/2, picWidth, picHeight);
        node.attachChild(startupQuad = getQuad("startup", startupPos));      
    }
    
    public void updateScreen(int percent, String text) {
        BufferedImage bi = new BufferedImage(picWidth, picHeight, BufferedImage.TYPE_INT_ARGB);
        Graphics2D bg = (Graphics2D) bi.getGraphics();
        bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        bg.setFont(FONT);
        
        bg.drawImage(image, 0, 0, null);
        
        int px = (picWidth - 200) / 2;
        int py = picHeight / 2;
        bg.setColor(new Color(20,20,20,130));
        bg.fillRoundRect(px, py, 200, 30, 5, 5);
        bg.setColor(new Color(255,0,0,180));
        bg.fillRoundRect(px, py, 2*percent, 30, 5, 5);
        bg.setColor(new Color(100,0,0,255));
        bg.setStroke(new BasicStroke(2));
        bg.drawRoundRect(px, py, 200, 30, 5, 5);
        
        bg.setColor(Color.WHITE);
        String percentString = "" + percent + "%";
        int percentWidth = bg.getFontMetrics().stringWidth(percentString);
        bg.drawString(percentString, (picWidth - percentWidth) / 2, py + 25);

        int textWidth = bg.getFontMetrics().stringWidth(text);
        bg.drawString(text, (picWidth - textWidth) / 2, py + 60);
        
        bg.dispose();
        
        setBufferedImage(bi, startupQuad);      
    }
}
